<?php
/**
 * Created by PhpStorm.
 * User: pankajmishra
 * Date: 17/01/15
 * Time: 11:14 AM
 */

namespace Application\Service;


class EmailService {


    public static $REGISTRATION_MESSAGE = 'Dear user,
              A warm welcome to bhaibandhu platform.
              Here you can do following things.
              Chat with your neighbours.
              Collaborate with your neighbours.
              Find information about your society and write some information that might be
              useful for your neighbours.
              Search member in your block or apartment.
              And there are many more options still to come. Please be tuned up.
              regards,
              Bhaibandhu Team.
              ';

    public static $PASSWORD_SECRET = 'Dear user,
                                         Your secret key is #secret#
                                            ';


    public static $INVITATION = 'Dear member,
                                 I am, #inviter_name# ,extending this invitation to join this
                                 wonderful online tool bhaibandhu. Please signup and be a
                                 part of our apartments online messaging and collaborating platform.
                                 This empowers you as a group by enabling you with
                                 every day updates from your neighbours and collaborate with them, chat
                                 and get their views by creating poll.


                                 You can click following link to signup.

                                 #link# ';


    public function sendEmail($to, $from_user,
                              $subject = '(Greetings from Bhaibandhu)', $message = ''){

        $from_user = 'support@bhaibandhu.com';

        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu<' . $from_user.'>',
            'Reply-To: ' . $from_user,
            'Return-Path: ' . $from_user,
            'X-Mailer: PHP v' . phpversion()
        );

        return mail($to, $subject, $message, implode("\n", $headers));
    }


    public function sendSecreteEmail($to, $secret){



        $from_user = 'support@bhaibandhu.com';
        $subject ='Forget Password from bhaibandhu';
        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu<' . $from_user.'>',
            'Reply-To: ' . $from_user,
            'Return-Path: ' . $from_user,
            'X-Mailer: PHP v' . phpversion()
        );

        $body = str_replace('#secret#',$secret,EmailService::$PASSWORD_SECRET);

        return mail($to, $subject,$body , implode("\n", $headers));
    }


    public function sendRegistrationEmail($to){


        $from_user = 'support@bhaibandhu.com';
        $subject ='Greetings from BhaiBandhu';
        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu <' . $from_user.'>',
            'Reply-To: noreply <noreply@bhaibandhu.com>' ,
            'Return-Path: noreply <noreply@bhaibandhu.com>'
        );

        return mail($to, $subject, EmailService:: $REGISTRATION_MESSAGE, implode("\n", $headers));
    }


    public function sendInvitationEmail($from, $to, $secret, $invitor_id, $from_name){

        $from_user = 'support@bhaibandhu.com';
        $subject = 'Invitation to connect with your apartment';
        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu<' . $from_user.'>',
            'Reply-To: noreply <noreply@bhaibandhu.com>' ,
            'Return-Path: noreply <noreply@bhaibandhu.com>'
        );

        $link = 'http://bhaibandhu.com?inviter='.$invitor_id.'&secret='.urlencode($secret);
        $invitation = str_replace('#link#',$link,EmailService:: $INVITATION);
        $invitation = str_replace('#inviter_name#',$from_name,$invitation);
        return mail($to, $subject, $invitation , implode("\n", $headers));
    }


    public static $BLOCKED = ' Hi,
                               Please be informed that, because of some unwanted behaviour from
                               your side, out of #totalCount# people of your block , #count# people decided to
                               ban you. Since  number of banning people exceeds half of the #totalCount#
                               hence we have no choice but to ban you permanently hereafter you will not be able
                               to login to our site.

                               Thanks,
                               BB Team.
                               ';


    public function sendBlockedEmail($email, $blocked_count, $group_count){
        $from_user = 'alert@bhaibandhu.com';
        $subject = 'Alert from bhaibandhu';
        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu<' . $from_user.'>',
            'Reply-To: noreply <noreply@bhaibandhu.com>' ,
            'Return-Path: noreply <noreply@bhaibandhu.com>'
        );

        $blocked = str_replace('#totalCount#', $group_count ,EmailService:: $BLOCKED);
        $blocked = str_replace('#count#', $blocked_count ,$blocked);

        return mail($email, $subject, $blocked, implode("\n", $headers));
    }
    // send that you are block now.
    // send the procedure to get yourself unblocked.

    public static $BLOCKING = 'Hi,
                               Please be informed that, because of some unwanted behaviour from
                               your side, out of #totalCount# people of your block , #count# people decided to
                               bane you. If number of banning people exceeds half of the #totalCount#
                               then you will be parmanently removed from this site.
                               Please restore faith of your community member before you will be removed.

                               Thanks,
                                BB Team.
                                 ';


    public function sendBlockingEmail($email, $blocked_count, $group_count){
        $from_user = 'noreply@bhaibandhu.com';
        $subject = 'Alert from bhaibandhu';
        $headers    = array
        (
            'MIME-Version: 1.0',
            'Content-Type: text/plain; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . 'bhaibandhu.com' . '>',
            'From: Bhaibandhu<' . $from_user.'>',
            'Reply-To: noreply <noreply@bhaibandhu.com>' ,
            'Return-Path: noreply <noreply@bhaibandhu.com>'
        );
        $blocking = str_replace('#totalCount#', $group_count ,EmailService:: $BLOCKING);
        $blocking = str_replace('#count#', $blocked_count ,$blocking);

        return mail($email, $subject, $blocking, implode("\n", $headers));
    }

} 